package com.woniuxy.service.impl;

import com.woniuxy.dao.McarParkingMapper;
import com.woniuxy.dao.MerchantUsersMapper;
import com.woniuxy.dao.PermissionMapper;
import com.woniuxy.dao.PreOrderMapper;
import com.woniuxy.dto.MyDto;
import com.woniuxy.node.TreeNode;
import com.woniuxy.pojo.McarParking;
import com.woniuxy.pojo.Permission;
import com.woniuxy.service.WebService;
import com.woniuxy.util.TreeNodeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class WebServiceImpl implements WebService {
    @Autowired
    private PermissionMapper permissionMapper;
    @Autowired
    private PreOrderMapper preOrderMapper;
    @Autowired
    private McarParkingMapper mcarParkingMapper;
    @Autowired
    private MerchantUsersMapper merchantUsersMapper;
    @Override
    public  List<TreeNode> selectpermissionBypid(Integer uid) {
      List<Permission> permissions =permissionMapper.selectpermissionBypid(uid);
      List<TreeNode> lists=new ArrayList<>();
        for (Permission permission : permissions) {
            TreeNode z=new TreeNode();
            z.setTitle(permission.getName());
            z.setIcon(permission.getIcom());
            z.setHref(permission.getHref());
            z.setId(permission.getId());
            z.setPid(permission.getPid());
            if (permission.getOpen().equals("1")){
                z.setSpread(true);
            }else {
                z.setSpread(false);
            }
            lists.add(z);
        }

        List<TreeNode>   z = TreeNodeBuilder.build(lists,1);
        return z;
    }
//上架车位 ，总订单 平均租金，投诉订单。
    @Override
    public List<MyDto> indexlist(Integer uid) {
        List<MyDto> myDtos=new ArrayList<>();
         List<McarParking> list =mcarParkingMapper.findUserByuid(uid);
        List<Integer> zz=new ArrayList<>();
        for (McarParking mcarParking : list) {
          zz.add(mcarParking.getId());
        }
        //投诉订单
        List<Permission> nums1 =permissionMapper.selectNumByuid(zz);

       MyDto map=new MyDto(nums1.size(),"投诉订单");
         //上架车位
        Integer nums2=merchantUsersMapper.selectCarNums(uid);
        MyDto map1=new MyDto(nums2,"上架车位");
        myDtos.add(map);
        myDtos.add(map1);
        return myDtos;
    }
}
